<?php

namespace Modules\Wechat\Model\Data;

use S\WeChat as WeChat;
use S\WeChat\Util\AccountConfigurator;

class OfficialAccount extends Abstraction
{
    protected function init()
    {
        return $this;
    }


    public function getAll($handling_account = '', $whit_access_token = false)
    {
        $list = AccountConfigurator::getList();
        if ($handling_account) {
            foreach ($list as &$account) {
                $account['handling']     = $handling_account == $account['account'];
                $account['access_token'] = $whit_access_token
                    ? WeChat::app($account['account'])->access_token->getToken(false)
                    : '';
            }
        }
        return $list;
    }

    public function getDetail($account)
    {
        return AccountConfigurator::getDetail($account);
    }
}